import {
  prop_add_type_arr,
  req_info_add_type,
} from '../../Classes/cla_req_info_add_type';
import { sign_check_only_set_type_info } from './Classes/cla_sign_check_only_set_type_info';
import { sign_cur_type_info } from './Classes/cla_sign_cur_type_info';
import { get_db_cur_type } from './Func/get_db_cur_type';

export function sign_for_all_type_cur_uni_id(cur_info: req_info_add_type) {
  let cur_type_id: string;

  for (cur_type_id of cur_info[prop_add_type_arr]) {
    sign_only_set_cur_type(cur_type_id, cur_info);
  }
}

async function sign_only_set_cur_type(
  cur_type_id: string,
  cur_info: req_info_add_type
) {
  let db_cur_type = get_db_cur_type(cur_type_id);

  let sign_check_info = new sign_check_only_set_type_info(cur_info);

  let check_arr = await db_cur_type.find(sign_check_info).toArray();

  if (check_arr.length > 0) {
    return;
  }

  let sign_info = new sign_cur_type_info(cur_info);

  db_cur_type.insertOne(sign_info);
}
